<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
    <title>回调事件：渲染完成/用户输入/聚焦/失焦/选择文字/ESC/Ctrl+Enter - Vditor</title>
    <meta name="robots" content="index,follow,archive">
    <meta name="description"
          content="Vditor - 易于使用的 Markdown 编辑器，为适配不同的应用场景而生。它使用 TypeScript 实现，支持原生 JavaScript、Vue、React、Angular，提供桌面版。"/>
    <meta name="copyright" content="B3log"/>
    <link rel="canonical" href="https://b3log.org/vditor/demo/option-callback.html">
    <link rel="apple-touch-icon" href="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/images/brand/vditor-128.png">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta http-equiv="Window-target" content="_top"/>
    <link rel="icon" type="image/png" href="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/images/brand/vditor-128.png"/>
    <link rel="shortcut icon" type="image/x-icon" href="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/images/brand/vditor-512.png"/>
    <link type="text/css" rel="stylesheet" href="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@7582df6ba7d52434a3e229cdbd56a06ae62b45c6/src/css/base.css" charset="utf-8"/>

    <meta property="og:locale" content="zh_CN"/>
    <meta property="og:title" content="回调事件：渲染完成/用户输入/聚焦/失焦/选择文字/ESC/Ctrl+Enter - Vditor"/>
    <meta property="og:description"
          content="Vditor - 易于使用的 Markdown 编辑器，为适配不同的应用场景而生。它使用 TypeScript 实现，支持原生 JavaScript、Vue、React、Angular，提供桌面版。"/>
    <meta property="og:image" content="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/images/brand/vditor-128.png"/>
    <meta property="og:url" content="https://b3log.org/vditor"/>
    <meta property="og:site_name" content="B3log"/>
    <meta name="twitter:card" content="summary_large_image"/>
    <meta name="twitter:description"
          content="Vditor - 易于使用的 Markdown 编辑器，为适配不同的应用场景而生。它使用 TypeScript 实现，支持原生 JavaScript、Vue、React、Angular，提供桌面版。"/>
    <meta name="twitter:title" content="回调事件：渲染完成/用户输入/聚焦/失焦/选择文字/ESC/Ctrl+Enter - Vditor"/>
    <meta name="twitter:image" content="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/images/brand/vditor-128.png"/>
    <meta name="twitter:url" content="https://b3log.org/vditor"/>
    <meta name="twitter:site" content="@b3logos"/>
    <meta name="twitter:creator" content="@b3logos"/>
    <script src="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/vditor/vditor.js" defer></script>
    <style>
        .header {
            background-color: #fff;
            box-shadow: rgba(0, 0, 0, 0.05) 0 1px 7px;
            border-bottom: 1px solid #e1e4e8;
        }

        #log {
            margin-bottom: 20px;
            flex: 1;
            overflow: auto;
            height: 120px;
        }
    </style>
</head>
<body>
<div class="header fn-clear">
    <a class="header-logo" href="https://b3log.org/vditor">
        <img src="https://cdn.jsdelivr.net/gh/vanessa219/b3log-index@d6b3ad3964429fe682f3de3ff4a48b59ea3145d9/src/images/brand/vditor-128.png">
        <h1>Vditor</h1>
    </a>
    <div class="fn-clear">
        <a class="header-a" href="https://ld246.com/tag/vditor" target="_blank">社区</a>
        <a class="header-a header-red" target="_blank" href="https://ld246.com/article/1549638745630">API</a>
        <a class="header-a header-green current" href="index.html">Demo</a>
        <a class="header-a header-yellow" href="https://ld246.com/sponsor" target="_blank">成为赞助者</a>
    </div>
</div>
<div class="wrapper">
    <div class="fn-50"></div>
    相关 <a href="https://ld246.com/article/1549638745630#options" target="_blank">API</a>：
    options.after()，options.input()，options.focus()，options.blur()，options.select()，options.esc()，options.ctrlEnter()
    <div class="fn-50"></div>
    <div style="display: flex">
        <div>回调日志：</div>
        <div id="log" class="ft-fade"></div>
    </div>
    <div id="vditor"></div>
    <div id="vditorDemoCode" class="vditor-reset">
        <pre><code class="javascript">  const logElement = document.getElementById('log')
  new Vditor('vditor', {
    typewriterMode: true,
    after () {
      logElement.innerText = '渲染完成'
    },
    ctrlEnter (md) {
      logElement.innerText = '用户按下了 Ctrl+Enter，Markdown 内容为：\n' + md
    },
    input (md) {
      logElement.innerText = '用户进行了输入，Markdown 内容为：\n' + md
    },
    blur (md) {
      logElement.innerText = '用户离开了编辑器，Markdown 内容为：\n' + md
    },
    select (md) {
      logElement.innerText = '用户选中了一段文字，内容为：\n' + md
    },
    focus (md) {
      logElement.innerText = '用户选中了编辑器，Markdown 内容为：\n' + md
    },
    esc (md) {
      logElement.innerText = '用户按下了 ESC，Markdown 内容为：\n' + md
    },
  })
</code></pre>
    </div>
    <div class="fn-100"></div>
    <div class="fn-clear">
        <h2 class="fn-left">参与讨论</h2>
        <span class="fn-right" style="line-height: 36px" id="commentCnt"></span>
    </div>
    <div class="fn-50"></div>
    <div id="vditorComments"></div>
    <div class="fn-100"></div>
</div>
<!-- end main -->

<div class="footer">
    <div class="wrapper fn-clear">
        <a href="https://b3log.org">首页</a> &nbsp; &nbsp;
        <a href="https://ld246.com" target="_blank">社区</a> &nbsp; &nbsp;
        <a href="https://b3log.org/brand-marking.html">品牌标识</a> &nbsp; &nbsp;
        <a href="https://ld246.com/sponsor" target="_blank">成为赞助者</a>
        <div class="fn-right">
            <a href="https://beian.miit.gov.cn/" target="_blank">滇ICP备14007358号-1</a> &nbsp; &nbsp;
            © 2010-2021 云南链滴科技有限公司
        </div>
    </div>
</div>
<script>
  vditorScript = () => {
    const logElement = document.getElementById('log')
    new Vditor('vditor', {
      typewriterMode: true,
      after () {
        logElement.innerText = '渲染完成'
      },
      ctrlEnter (md) {
        logElement.innerText = '用户按下了 Ctrl+Enter，Markdown 内容为：\n' + md
      },
      input (md) {
        logElement.innerText = '用户进行了输入，Markdown 内容为：\n' + md
      },
      blur (md) {
        logElement.innerText = '用户离开了编辑器，Markdown 内容为：\n' + md
      },
      select (md) {
        logElement.innerText = '用户选中了一段文字，内容为：\n' + md
      },
      focus (md) {
        logElement.innerText = '用户选中了编辑器，Markdown 内容为：\n' + md
      },
      esc (md) {
        logElement.innerText = '用户按下了 ESC，Markdown 内容为：\n' + md
      },
    })
  }
</script>
</body>
</html>
